import os
import fileinput

if __name__ == '__main__':
    def replace_first_char(folder_path, number):
        for root, dirs, files in os.walk(folder_path):
            for file in files:
                if file.endswith(".txt"):
                    file_path = os.path.join(root, file)
                    with fileinput.FileInput(file_path, inplace=True) as f:
                        for line in f:
                            print(str(number) + line[1:], end='')

    # 示例用法
    replace_first_char("C:/Users/64531/Desktop/weed-datasets/corn weed datasets/bluegrass/label", 0)
    replace_first_char("C:/Users/64531/Desktop/weed-datasets/corn weed datasets/chenopodium album/label", 0)
    replace_first_char("C:/Users/64531/Desktop/weed-datasets/corn weed datasets/cirsium setosum/label", 0)
    replace_first_char("C:/Users/64531/Desktop/weed-datasets/corn weed datasets/corn/label", 0)